package com.active.hackson.app.beans.grid;

import java.util.ArrayList;
import java.util.List;


public class ResponseTableModel {

  private String page; // get the requested page(current page)
  private int total;
  private int records;
  private String userdata;
  private List rows = new ArrayList();

  //  you should always provide request model and data to build grid.
  private void ResponseTableModel() {}

  public ResponseTableModel( RequestTableModel reqModel, List datas ) {

    if(reqModel.getRows() == null) {
      reqModel.setRows( 20 );
    }
    if(reqModel.getPage() == null) {
      reqModel.setPage( "1" );
    }
    
    int pageSize = reqModel.getRows();
    int totalSize = datas.size();

    int totalPage = ( totalSize % pageSize == 0 ) ? ( totalSize / pageSize ) : ( totalSize / pageSize + 1 );

    setPage( reqModel.getPage() );
    setTotal( totalPage );
    setRecords( totalSize );

    setRows( datas );
    setUserdata( "" );
  }

  public ResponseTableModel( RequestTableModel reqModel, List datas, String userData ) {
    this( reqModel, datas );
    setUserdata( userData );
  }


  public String getPage() {
    return page;
  }

  public void setPage( String page ) {
    this.page = page;
  }

  public int getTotal() {
    return total;
  }


  public void setTotal( int total ) {
    this.total = total;
  }


  public int getRecords() {
    return records;
  }


  public void setRecords( int records ) {
    this.records = records;
  }

  public List getRows() {
    return rows;
  }


  public void setRows( List rows ) {
    this.rows = rows;
  }

  public String getUserdata() {
    return userdata;
  }

  public void setUserdata( String userdata ) {
    this.userdata = userdata;
  }

}
